package com.salefinder.client;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FormButtonBinding;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.google.gwt.user.client.Element;




public class HomeScreen extends LayoutContainer {

	@Override
	protected void onRender(Element parent, int index) { 
		super.onRender(parent, index);
		this.setLayout(new FitLayout());
		VerticalPanel hp = new VerticalPanel();
//		hp.setSpacing(10);
		
		FormPanel searchPanel = new FormPanel();
		searchPanel.setHeading("Searh a product");

		FormData formData = new FormData("-20");

		SimpleComboBox<String> areaOption = new SimpleComboBox<String>();
		areaOption.add("Toronto");
		areaOption.add("Mississuaga");
		areaOption.add("Richmond Hill");
		areaOption.setFieldLabel("Location");
		searchPanel.add(areaOption, formData);

		SimpleComboBox<String> name = new SimpleComboBox<String>();
		name.add(Suggestion.productNameSuggestions);
		name.setFieldLabel("Product");
		searchPanel.add(name, formData);

		Button b = new Button("Search");  
		searchPanel.addButton(b);
		searchPanel.setButtonAlign(HorizontalAlignment.CENTER); 

		FormButtonBinding binding = new FormButtonBinding(searchPanel);  
		binding.addButton(b);
		
		b.addListener (Events.OnClick, new Listener<ButtonEvent>(){

			@Override
			public void handleEvent(ButtonEvent be) {
				SaleFinder.master.updateCurrentScreen(Controller.getSearchResultsScreen());
				
			}
			
		});
		
		hp.add(searchPanel);
		this.add(hp);

	}

}
